home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / CIncludes / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-21  |  7.6 KB  |  325 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     StdIO.h
  4.     Input / output
  5.     
  6.     Copyright © Apple Computer,Inc.  1985-1991, 1993-1994.
  7.  
  8.     Copyright American Telephone & Telegraph
  9.     Used with permission, Apple Computer Inc. (1985)
  10.     All Rights Reserved.
  11.  
  12. ************************************************************/
  13.  
  14. /* Conditional Macros:
  15.  *    UsingStaticLibs    - for CFM-68K:  Insures that #pragma lib_export is never used.
  16.  *    UsingSharedLibs    - for CFM-68K:  Insures that all functions and data items are
  17.  *                                    marked as exported
  18.  *    <none>            - for CFM-68K:    Data items are exported using #pragma lib_export,
  19.  *                                    functions are not.  Causes excess code to be
  20.  *                                    generated for data references to static libraries
  21.  *                                    and causes the linker to generate glue for
  22.  *                                    references to shared library routines.
  23.  *    The preceeding macros may not both be defined in the same compilation.
  24.  */
  25. #if defined (UsingStaticLibs) && defined (UsingSharedLibs)
  26.     #error "Only one of the conditional macros 'UsingStaticLibs' and 'UsingSharedLibs' may be defined in a compilation"
  27. #endif
  28.  
  29. #ifndef __STDIO__
  30. #define __STDIO__
  31.  
  32. #ifndef NULL
  33. #define NULL 0
  34. #endif
  35.  
  36. #ifndef __size_t__
  37. #define __size_t__
  38. typedef unsigned int size_t;
  39. #endif
  40.  
  41. #ifndef __va_list__
  42. #define __va_list__
  43. typedef char *va_list;
  44. #endif
  45.  
  46.  
  47. /*
  48.  *    The basic data structure for a stream is the FILE.
  49.  */
  50.  
  51. #ifdef powerc
  52. #pragma options align=power
  53. #endif
  54. struct FILE {
  55.     int             _cnt;
  56.     unsigned char    *_ptr;
  57.     unsigned char    *_base;
  58.     unsigned char    *_end;
  59.     unsigned short    _size;
  60.     unsigned short    _flag;
  61.     unsigned short    _file;
  62. };
  63. #ifdef powerc
  64. #pragma options align=reset
  65. #endif
  66. typedef struct FILE FILE;
  67.  
  68.  
  69. /*
  70.  *    fpos_t is a type that can express any position in a file.  A file's
  71.  *    end-of-file marker has type fpos_t.
  72.  */
  73.  
  74. typedef long fpos_t;
  75.  
  76.  
  77. /*
  78.  *    These macros give the meanings of bits in a FILE's _flag.  setvbuf() takes
  79.  *    one of _IOFBF, _IOLBF, or _IONBF as its third argument.
  80.  */
  81.  
  82. #define _IOFBF        0            /* Pseudo-flag, default buffering style */
  83. #define _IOREAD     (1<<0)        /* Current mode is for reading */
  84. #define _IOWRT        (1<<1)        /* Current mode is for writing */
  85. #define _IONBF        (1<<2)        /* no buffering */
  86. #define _IOMYBUF    (1<<3)        /* buffer was allocated by stdio */
  87. #define _IOEOF        (1<<4)
  88. #define _IOERR        (1<<5)
  89. #define _IOLBF        (1<<6)        /* fflush(iop) when a \n is written */
  90. #define _IORW        (1<<7)        /* Enable read/write access */
  91. #define _IOSYNC        (1<<8)        /* Input triggers fflush() to output fp's */
  92. #define _IOBINARY    (1<<9)        /* Binary stream */
  93. #define _IOBACK        (1<<14)        /* Result of "ungetc() is in the buffer */ 
  94.  
  95.  
  96. /*
  97.  *    Default file buffer sizes used by setbuf() and setvbuf().
  98.  */
  99.  
  100. #define BUFSIZ    1024            /* default file buffer size */
  101. #define _LBFSIZ  254            /* Line buffer size */
  102.  
  103.  
  104. /*
  105.  *    The standard end-of-file indicator.
  106.  */
  107.  
  108. #define EOF        (-1)
  109.  
  110.  
  111. /*
  112.  *    L_tmpnam is the size of char array long enough to hold a temporary file name
  113.  *    generated by tmpnam(), including the trailing null byte.  The name is in the
  114.  *    form tmp.AAAXXXXXX, where AAA is a sequence of lower case letters ("aaa", "baa",
  115.  *    ... "zzz" on successive calls), and XXXXXX is a lower case letter followed by a sequence
  116.  *    of digits, all determined at runtime.
  117.  *    TMP_MAX is the number of distinct file names that tmpnam() can generate.
  118.  */
  119.  
  120. #define L_tmpnam    14
  121. #define TMP_MAX        17576
  122.  
  123.  
  124. /*
  125.  *    The minimum number of files that a program is guaranteed to be able to have
  126.  *    open simultaneously (including the pre-opened stdin, stdout, and stderr).
  127.  *    The numbers are listed in Inside Macintosh, page IV-178, as:
  128.  *    64K ROM, 128K Macintosh        12 files
  129.  *    64K ROM, 512K Macintosh        40 files
  130.  *    128K ROM                    40 files per volume
  131.  */
  132.  
  133. #define FOPEN_MAX    12
  134.  
  135.  
  136. /*
  137.  *    Maximum length of a file name, including a trailing zero byte.
  138.  */
  139.  
  140. #define FILENAME_MAX    32
  141.  
  142.  
  143. /*
  144.  *    For use by fseek():
  145.  */
  146.  
  147. #ifndef __FCNTL__            /* these defns exactly paralled in FCntl.h for lseek() */
  148.  
  149. #define SEEK_CUR    1
  150. #define SEEK_END    2
  151. #define SEEK_SET    0
  152.  
  153. #endif
  154.  
  155.  
  156. /*
  157.  *    The standard predefined streams.
  158.  */
  159.  
  160. #define stdin        (&_iob[0])
  161. #define stdout        (&_iob[1])
  162. #define stderr        (&_iob[2])
  163.  
  164.  
  165. #ifdef __cplusplus
  166. extern "C" {
  167. #endif
  168.  
  169. #ifdef __CFM68K__
  170.     #ifdef UsingSharedLibs
  171.         #pragma lib_export on
  172.         #define    _EXP_ON_
  173.     #endif
  174. #endif
  175.  
  176. /*
  177.  *    Operations on files
  178.  */
  179.  
  180. int remove(const char *filename);
  181. int rename(const char *oldname, const char *newname);
  182. FILE *tmpfile(void);
  183. char *tmpnam(char *s);
  184.  
  185.  
  186. /*
  187.  *    File access functions
  188.  */
  189.  
  190. int fclose(FILE *stream);
  191. int fflush(FILE *stream);
  192. FILE *fopen(const char *filename, const char *mode);
  193. FILE *freopen(const char *filename, const char *mode, FILE *stream);
  194. void setbuf(FILE *stream, char *buf);
  195. int setvbuf(FILE *stream, char *buf, int mode, size_t size);
  196.  
  197.  
  198. /*
  199.  *    Formatted input/output functions
  200.  */
  201.  
  202. int fprintf(FILE *stream, const char *format, ...);
  203. int fscanf(FILE *stream, const char *format, ...);
  204. int printf(const char *format, ...);
  205. int scanf(const char *format, ...);
  206. int sprintf(char *s, const char *format, ...);
  207. int sscanf(const char *s, const char *format, ...);
  208. int vfprintf(FILE *stream, const char *format, va_list arg);
  209. int vprintf(const char *format, va_list arg);
  210. int vsprintf(char *s, const char *format, va_list arg);
  211.  
  212.  
  213. /*
  214.  *    Character input/output functions and macros
  215.  */
  216.  
  217. int fgetc(FILE *stream);
  218. char *fgets(char *s, int n, FILE *stream);
  219. int fputc(int c, FILE *stream);
  220. int fputs(const char *s, FILE *stream);
  221. int getc(FILE *stream);
  222. #define getc(p)     (--(p)->_cnt >= 0 ? (int) *(p)->_ptr++ : _filbuf(p))
  223. int getchar(void);
  224. #define getchar()    getc(stdin)
  225. char *gets(char *s);
  226. int putc(int c, FILE *stream);
  227. #define putc(x, p)    (--(p)->_cnt >= 0 ? \
  228.                         ((int) (*(p)->_ptr++ = (unsigned char) (x))) : \
  229.                         _flsbuf((unsigned char) (x), (p)))
  230. int putchar(int c);
  231. #define putchar(x)    putc((x), stdout)
  232. int puts(const char *s);
  233. int ungetc(int c, FILE *stream);
  234.  
  235.  
  236. /*
  237.  *    Direct input/output functions
  238.  */
  239.  
  240. size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
  241. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  242.  
  243.  
  244. /*
  245.  *    File positioning functions
  246.  */
  247.  
  248. int fgetpos(FILE *stream, fpos_t *pos);
  249. int fseek(FILE *stream, long int offset, int whence);
  250. int fsetpos(FILE *stream, const fpos_t *pos);
  251. long int ftell(FILE *stream);
  252. void rewind(FILE *stream);
  253.  
  254.  
  255. /*
  256.  *    Error-handling functions and macros
  257.  */
  258.  
  259. void clearerr(FILE *stream);
  260. #define clearerr(p) ((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
  261. int feof(FILE *stream);
  262. #define feof(p)     ((p)->_flag & _IOEOF)
  263. int ferror(FILE *stream);
  264. #define ferror(p)    ((p)->_flag & _IOERR)
  265. void perror(const char *s);
  266.  
  267. /*
  268.  * For macros
  269.  */
  270.  
  271. #ifdef __CFM68K__
  272.     #if ! defined(UsingStaticLibs) && ! defined(_EXP_ON_)
  273.         #pragma lib_export on
  274.         #define    _EXP_ON_
  275.     #endif
  276. #endif
  277.  
  278. extern FILE _iob[];
  279.  
  280. #ifdef __CFM68K__
  281.     #if    ! defined(UsingSharedLibs) && defined(_EXP_ON_)
  282.         #pragma lib_export off
  283.         #undef    _EXP_ON_
  284.     #endif
  285. #endif
  286.  
  287. #define _NFILE 40
  288. int _filbuf(FILE *);
  289. int _flsbuf(unsigned char, FILE *);
  290.  
  291. /*
  292.  *    Non-ANSI extensions
  293.  *
  294.  * The prefered mechanism for enabling these is by defining __useAppleExts__.  
  295.  * In the absence of this symbol, the __STDC__ symbol is used to enable or
  296.  * disable these extentions.
  297.  */
  298.  
  299. /* CFront can't handle the pretty version of this conditional 
  300. #if defined (__useAppleExts__) || \
  301.     ((defined (applec) && ! defined (__STDC__)) || \
  302.      (defined (__PPCC__) && __STDC__ == 0))
  303. */
  304. #if defined (__useAppleExts__) || ((defined (applec) && ! defined (__STDC__)) || (defined (__PPCC__) && __STDC__ == 0))
  305.  
  306. #define fileno(p)    (p)->_file
  307. FILE *fdopen(int fildes, const char *mode);
  308. void fsetfileinfo (char *filename, unsigned long newcreator, unsigned long newtype);
  309. int getw(FILE *stream);
  310. int putw(int w, FILE *stream);
  311.  
  312. #endif
  313.  
  314. #ifdef _EXP_ON_
  315.     #pragma lib_export off
  316.     #undef    _EXP_ON_
  317. #endif
  318.  
  319. #ifdef __cplusplus
  320. }
  321. #endif
  322.  
  323.  
  324. #endif
  325.